<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>完善当当购物车页面</title>
    <link type="text/css" rel="stylesheet" href="css/cartStyle.css" />

    <script>

        function close_plan() {
            if(confirm("是否关闭窗口？")){
                window.close();
            }
        }
        function collection() {
            if(confirm("是否移入收藏？")){
                alert("收藏成功！");
            }
        }
        function del() {
            if(confirm("是否删除？")){
                alert("删除成功！");
            }
        }
        function accounts() {
            if(confirm("是否结算？")){
                alert("结算成功！");
                open("https://wwww.baidu.com/")
            }
        }

        function minus(i) {
            var price=document.getElementsByName("price")[i].value;//价格
            var amount=document.getElementsByName("amount")[i].value;//数量
            if(amount<=0){
                return;
            }
            amount--;
            document.getElementsByName("amount")[i].value=amount;
            var money=parseFloat(price)*parseInt(amount);
            var li=document.getElementById("price"+i).innerHTML='￥'+money;
            totalCalc();
        }

        function plus(i) {
            var price=document.getElementsByName("price")[i].value;//价格
            var amount=document.getElementsByName("amount")[i].value;//数量
            amount++;
            document.getElementsByName("amount")[i].value=amount;
            var money=parseFloat(price)*parseInt(amount);
            var li=document.getElementById("price"+i).innerHTML='￥'+money;
            totalCalc();
        }
        function totalCalc(){
            var money=0;
          for (var i=1;i<=2;i++){
              var price=document.getElementsByName("price")[i].value;//价格
              var amount=document.getElementsByName("amount")[i].value;//数量
              money+=parseFloat(price)*parseInt(amount);
          }
            document.getElementById("totalPrice").innerHTML='￥'+money;


        }
        totalCalc();


    </script>


</head>
<body>

<div class="content">
    <div class="logo">
        <img src="images/dd_logo.jpg"><span onclick="close_plan();">关闭</span>
    </div>
    <div class="cartList">
        <ul>
            <li>¥<input type="text" name="price" value="21.90"></li>
            <li><input type="button" name="minus" value="-" onclick="minus(0);"><input type="text" name="amount" value="1"><input type="button" name="plus" value="+" onclick="plus(0);"></li>
            <li id="price0">¥21.90</li>
            <li><p  onclick="collection();">移入收藏</p><p onclick="del();">删除</p></li>
        </ul>
        <ul>
            <li>¥<input type="text" name="price" value="24.00"></li>
            <li><input type="button" name="minus" value="-" onclick="minus(1);"><input type="text" name="amount" value="1"><input type="button" name="plus" value="+" onclick="plus(1);"></li>
            <li id="price1">¥24.00</li>
            <li><p  onclick="collection();">移入收藏</p><p onclick="del();">删除</p></li>
        </ul>
        <ol>
            <li id="totalPrice">&nbsp;</li>
            <li><span onclick="accounts();">结 算</span></li>
        </ol>
    </div>
</div>
<script type="text/javascript" src="js/shopping.js"></script>
</body>
</html>